#version 450 compatibility



#define M_PI 3.1415926535897
#define M_2PI 6.2831853071795

layout(local_size_x = DEF_LocalSize, local_size_y = DEF_LocalSize, local_size_z = 1) in;

layout( binding = 0, rgba8ui) uniform uimage2D Pix;

layout( binding = 1 ) uniform Buf_LoalParameter0 {
    uint    m_Frequency;    //频率
    float   m_Intensity;    //强度
    int     m_WaveOffset;   //波形偏移
          
    uint    m_Sampling;     //采样

    ivec4   m_Box;
    ivec4   m_Offset_Size;
};



void main(){
    ivec2 coord = ivec2(0,0);
    coord.x = int(gl_WorkGroupID.x);
    //coord += m_Offset_Size.xy;
    coord += m_Box.xy;

    if(coord.x >= m_Box.x && coord.x < m_Box.z){
        float scale = float(m_Sampling) / float(m_Offset_Size.z);

        float sp = M_2PI / (float(m_Sampling) / float(m_Frequency));
        float offset = m_WaveOffset + int(gl_WorkGroupID.x);
        if(m_Offset_Size.x < 0){
            offset -= m_Offset_Size.x;
        }
        sp = sin(sp * offset * scale);

        float height = (float(m_Offset_Size.w - 8))/2.0;
        coord.y += int(height * sp);
        coord.y += m_Offset_Size.w/2;

        if(coord.y >= m_Box.y && coord.y < m_Box.w){
            uvec4 c = uvec4(255, 255, 10, 255);
            imageStore(Pix, coord, c);
        }        
        
    }

}





